package warmup.quicksort;



/* Head ends here */
import java.util.*;
public class Solution {
       
    static void quickSort(int[] ar, int initial, int last) {
    	if(initial > last) {
    		return;
    	}
//              sort(ar,0,ar.length-1);
    	 int partition = partition(ar,initial,last);
    	 printArray(ar,initial,last);
    	 quickSort(ar,initial,partition-1);    	 
    	 quickSort(ar,partition+1,last);
    	
    	 
     }   
    
    public static void sort(int[] arr, int initial, int last)
	{
		int left = initial, right = last;
		int pivot = arr[initial + (last - initial)/2];
		
		while (left <  right){
			
			while(arr[left] < pivot){
				left++;
				
			}
			while(arr[right] > pivot){
				right--;
				
			}
			if(left <= right){
				swap(arr,left,right);
				left++;
				right--;
			}
		}
		if(initial < right){
			sort(arr, initial, right);
			printArray(arr,initial,right);
		}
		
		if(left < last){
			sort(arr,left, last);
			printArray(arr,left,last);
		}		
	}
	
	public static void swap(int[] arr, int i, int j){
		int temp = arr[i];
		arr[i] = arr[j];
		arr[j] =temp;
	}

static int partition(int[] arr, int initial, int last){
	
	int pivotindex = initial + (last - initial)/2;
	int pivot = arr[initial + (last - initial)/2];
	int j = initial +1;
	int i = initial;
	swap(arr, pivotindex, initial);
	for (;j <= last ; j++){
		
		if(arr[j] <= pivot) {
			i++;
			swap(arr, i, j);			
		}
	}
	
	if(i > initial){
		swap(arr,i,initial);
	}
	return i;
}

static int partition_last_pivot(int[] arr, int initial, int last){
	
	int pivotIndex= initial + (last - initial)/2;
	int pivot = arr[pivotIndex];
	swap(arr, pivotIndex, last);
	
	int j = initial;
	int i = initial;
	
	for (;j < last ; j++){
		
		if(arr[j] <= pivot) {
			i++;
			swap(arr, i, j);
			
		}
	}
	swap(arr,i,last);
	
	return i;
}
    /* Tail starts here */
 
 static void printArray(int[] ar) {
         for(int n: ar){
            System.out.print(n+" ");
         }
           System.out.println("");
      }
 static void printArray(int[] ar,int i, int j) {
     for(;i <=j;i++){
        System.out.print(ar[i]+" ");
     }
       System.out.println("");
  } 
      public static void main(String[] args) {
           Scanner in = new Scanner(System.in);
           int n = in.nextInt();
           int[] ar = new int[n];
           for(int i=0;i<n;i++){
              ar[i]=in.nextInt(); 
           }
           quickSort(ar,0,ar.length-1);
                      
           printArray(ar);	
       }    
   }
